<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="UTF-8">
<title>日志管理</title>
<link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
</head>
<body>
	<!-- 搜索开始 -->
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  		<legend>查询条件</legend>
	</fieldset>
	<form class="layui-form" action="" id="searchFrm">
		<div class="layui-form-item" style="text-align: center">
		    <div class="layui-inline">
		      <label class="layui-form-label">登陆名称</label>
		      <div class="layui-input-inline">
		        <input type="text" name="loginname"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">开始时间</label>
		      <div class="layui-input-inline">
		        <input type="text" name="startTime"   autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-inline">
		      <label class="layui-form-label">结束时间</label>
		      <div class="layui-input-inline">
		        <input type="text" name="endTime"  autocomplete="off" class="layui-input">
		      </div>
		    </div>
	  </div>
	  <div class="layui-form-item" style="text-align: center;">
		    <div class="layui-input-block">
		      <button type="button" class="layui-btn" id="doSearch">查询</button>
		      <button type="reset" class="layui-btn layui-btn-primary" >重置</button>
		    </div>
  	 </div>
	</form>
	<!-- 搜索结束-->
	<table class="layui-hide" id="loginfoList" lay-filter="loginfoList"></table>
	<div id="tabr" style="display: none;">
		<button type="button" class="layui-btn layui-btn-sm  layui-btn-danger" lay-event="bacthdelete" shiro:hasPermission="info:batchdelete">批量删除</button>
	</div>
	<div id="tableCellToolBar" style="display: none;">
		<button type="button" class="layui-btn layui-btn-sm  layui-btn-danger" lay-event="del" shiro:hasPermission="info:delete">删除</button>
	</div>
</body>
<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
layui.use([ 'layer', 'jquery', 'table', 'form' ], function() {
	var layer = layui.layer;
	var $ = layui.jquery;
	var table = layui.table;
	var from = layui.form;
	//渲染表格
	 var tableIns = table.render({
		elem : '#loginfoList' //渲染表格的容器
		,
		url : '/loginfo/loadAllLogInfo' //请求数据的地址
		,
		cellMinWidth : 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
		,
		page : true //开启分页
		,
		defaultToolbar : [ 'filter', 'print' ] //设置工具栏的位置和是否显示
		,
		height:'430px',
		toolbar:'#tabr',
		cols : [ [ {
			type : 'checkbox',
			width:  100
		}, {
			field : 'id',
			width : 195,
			title : '日志ID',
			align : 'center'
		}, {
			field : 'loginname',
			width : 250,
			title : '登陆名称',
			align : 'center'
		}, {
			field : 'loginip',
			width : 250,
			title : '登陆IP',
			align : 'center'
		}, {
			field : 'logintime',
			width : 250,
			title : '登陆时间',
			align : 'center'
		},{
			width : 250,
			title : '操作',
			align : 'center',
			toolbar : "#tableCellToolBar",
			fixed : 'right',
			align : 'center'
		} ] ]
	});

	//刷新表格
	$("#doSearch").click(function() {
		var params=$("#searchFrm").serialize();
		tableIns.reload({
			url : '/loginfo/loadAllLogInfo?'+params,
			page : {
				curr : 1
			}
		});
	});
	
	table.on('toolbar(loginfoList)', function(obj){
		  switch(obj.event){
		    case 'bacthdelete':
		      bacthDelete();
		    break;
		    
		  };
		});
	
	function bacthDelete(){
			   var checkStatus = table.checkStatus('loginfoList');
				var data = checkStatus.data;
				if(data.length>0){
					  layer.confirm('确定要删除选中的所有登陆日志么', function(index){
							var params = "";
							for(var i=0;i<data.length;i++){
								if(i==0){
									params += "?ids="+data[i].id;
								}else{
									params += "&ids="+data[i].id;
								}
							}
							alert(params)
							$.post("/loginfo/batchDelete"+params,function(obj){
								layer.msg(obj.msg);
					            tableIns.reload();
					            layer.close(index);
							});
					    });
				}else{
					layer.msg("请选中要删除的日志")
				}
		 
	}
	
	
	table.on('tool(loginfoList)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		  var data = obj.data; //获得当前行数据
		  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		 
		 if(layEvent === 'del'){ //删除
		    layer.confirm('确定要删除['+data.loginname+']这条登陆日志么', function(index){
		    	$.post("/loginfo/deleteLogInfo",{id:data.id},function(obj){
		      		layer.msg(obj.msg);
		            tableIns.reload();
		            layer.close(index);
		      	});
		    });
		  }
		});

});
</script>
</html>